package code.generate.singleton;

import java.util.HashMap;

public class SingletonRegistry {
        public static SingletonRegistry REGISTRY = new SingletonRegistry();

        private static HashMap<String, Object> map = new HashMap<String, Object>();

        protected SingletonRegistry() {
                // Exists to defeat instantiation
        }

        public static synchronized Object getInstance(String classname) {
                Object singleton = map.get(classname);

                if (singleton != null) {
                        return singleton;
                }
                try {
                        singleton = Class.forName(classname).newInstance();
                } catch (Exception cnf) {
                }
                map.put(classname, singleton);
                return singleton;
        }
}